package com.inno.log.entity;


import com.inno.log.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonReturnType<T> {
    private Integer code;
    private String message;
    private T content;
    public static <T> CommonReturnType<T> success(T data) {
        CommonReturnType<T> type = new CommonReturnType<>();
        type.setCode(ResultCodeEnum.SUCCESS.getCode());
        type.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        type.setContent(data);
        return type;
    }
    public static <T> CommonReturnType<T> success(){
        return success(null);
    }




    public static <T> CommonReturnType<T> fail() {
        return new CommonReturnType<>(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getDesc(), null);
    }

    public static <T> CommonReturnType<T> fail(String message) {
        CommonReturnType<T> type = new CommonReturnType<>();
        type.setCode(ResultCodeEnum.FAIL.getCode());
        type.setMessage(message);
        type.setContent(null);
        return type;
    }

    public static <T> CommonReturnType<T> fail(Integer code, String message) {
        CommonReturnType<T> type = new CommonReturnType<>();
        type.setCode(code);
        type.setMessage(message);
        type.setContent(null);
        return type;
    }

}
